package com.example.yuntiku.Servlet;

import com.example.yuntiku.Service.ExamanwerService;
import com.example.yuntiku.entity.Examanwer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "ExamanwerServlet", value = "/ExamanwerServlet")
public class ExamanwerServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        Integer testrescordid = Integer.valueOf(request.getParameter("list"));
        String topic = request.getParameter("topic");
        ExamanwerService examanwerService = new ExamanwerService();
        List<Examanwer> list = examanwerService.selectBctim(testrescordid);
        int i = 0;
        int dadueishu = 0;
        for (Examanwer examanwer : list) {
            i++;
            //String 的对比要用.equals()对比的值给包裹起来
            if(examanwer.getChooseanswer().equals(examanwer.getRightanswers())){
                dadueishu++;
            }
        }
        request.setAttribute("topic",topic);
        request.setAttribute("testrescordid",testrescordid);
        request.setAttribute("shutusgu",i);
        request.setAttribute("xiangxxx",list);
        request.setAttribute("dadueishu",dadueishu);
        request.getRequestDispatcher("AnswerResult.jsp").forward(request,response);
    }
}